/*
 * FontChooserDelegate.cpp  0.4.0 / Nov 17, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "FontChooserDelegate.h"

#include "ComponentDelegate.h"

// FontChooserDelegate :: Static Native Calls. ---------------------------------

/*!
 * \brief Returns font selected by the user.
 *
 * \param env the JNIEnv pointer
 * \param cls the FontChooser java class
 * \param parentDelegate the parent widget delegate
 * \param initialFont the initial font
 * \param title the dialog title
 * 
 * \return font selected by the user
 */
jobject FontChooserDelegate::getFont(JNIEnv *env, jclass cls,
                                     jlong parentDelegate, jobject initialFont,
                                     jstring title)
{
  Q_ASSERT(env);
  SWING_STATIC_REENTRANT_RETURN(FontChooserDelegate, getFont, jobject,
                                SWING_ENV_ARG, JCLASS_ARG(cls),
                                JLONG_ARG(parentDelegate),
                                JOBJECT_ARG(initialFont),
                                JSTRING_ARG(title))
  QWidget *parent = 0;
  if (parentDelegate) {
    parent = COMPONENT_CAST(parentDelegate)->qWidget();
  }
  QFont defaltFont;
  if (initialFont) {
    defaltFont = *QFontAdapter::toQFont(env, initialFont);
  }
  bool accepted;
  QFont selectedFont = QFontDialog::getFont(&accepted, defaltFont, parent,
                                            QStringAdapter(env, title));
  if (accepted) {
    return QFontAdapter::toJFont(selectedFont);
  }
  return 0;
}
